package org.jpass.dc.business.user.bean;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;
import org.jpass.dc.common.bean.UUIDSupport;

@Entity
@Table(name = "t_user")
@SuppressWarnings("serial")
public class UserVOBean extends UUIDSupport implements Serializable {

	private UserGroupVOBean group;
	private String email; // 注册email，即登录名称
	private String username; // 用户昵称
	private String realName; // 用户真实姓名
	private String password; // 登录密码
	private String sex;
	private Date birthday;
	private Date createdDate; // 注册时间
	private String workPath; // 项目存放的路径
	private Integer point; // 用户积分
	private Integer isMember; // 是否为会员
	private Date memBeginTime; // 会员开始时间
	private Date memEndTime; // 会员到期时间
	private Integer isOnline; // 是否在线
	private Integer loginTimes; // 最后登录时间
	private Date lastSignTime; // 上次登录时间
	private Date thisSignTime; // 本次登录时间
	private Integer isActivated; // 是否激活
	private String token; // 激活码
	private Date sendEmailTime; // 激活邮件发送时间
	private Date sendForgetEmailTime; // 忘记密码邮件发送时间
	private String notes; // 备注
	
	public UserVOBean() {
	}

	public UserVOBean(String id, String username, String password,
			String email, String workPath, Date createdDate, String sex,
			Date birthday, Integer point, Integer isMember, Integer isOnline,
			Date lastSignTime, String notes) {
		this.email = email;
		this.username = username;
		this.password = password;
		this.sex = sex;
		this.birthday = birthday;
		this.createdDate = createdDate;
		this.workPath = workPath;
		this.point = point;
		this.isMember = isMember;
		this.isOnline = isOnline;
		this.lastSignTime = lastSignTime;
		this.notes = notes;
	}

	public UserVOBean(
			String id, 
			String username, 
			String password,
			String email, 
			String sex, 
			Date birthday, 
			Integer point,
			String groupName, 
			String workPath, 
			Date createdDate,
			Integer isActivated, 
			Integer isMember, 
			Date memBeginTime, 
			Date memEndTime,
			Integer isOnline, 
			Integer loginTimes, 
			Date lastSignTime,
			String notes) {
		this.email = email;
		this.username = username;
		this.password = password;
		this.sex = sex;
		this.birthday = birthday;
		this.createdDate = createdDate;
		this.workPath = workPath;
		this.point = point;
		this.isMember = isMember;
		this.isOnline = isOnline;
		this.lastSignTime = lastSignTime;
		this.notes = notes;
	}

	@Column(name = "username", nullable = false)
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	@Column(name = "realName", nullable = true)
	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	@Column(name = "password", nullable = false)
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name = "email", nullable = false, updatable = false)
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Column(name = "workPath", nullable = false, length = 100)
	public String getWorkPath() {
		return workPath;
	}

	public void setWorkPath(String workPath) {
		this.workPath = workPath;
	}

	@Column(name = "createdDate", nullable = true)
	public Date getCreatedDate() {
		return createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	@Column(name = "sex", nullable = true)
	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	@Column(name = "birthday", nullable = true)
	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	@Column(name = "point", nullable = true)
	public Integer getPoint() {
		return point;
	}

	public void setPoint(Integer point) {
		this.point = point;
	}

	@Column(name = "isMember", nullable = true)
	public Integer getIsMember() {
		return isMember;
	}

	public void setIsMember(Integer isMember) {
		this.isMember = isMember;
	}

	@Column(name = "isActivated", nullable = true)
	public Integer getIsActivated() {
		return isActivated;
	}

	public void setIsActivated(Integer isActivated) {
		this.isActivated = isActivated;
	}

	@Column(name = "token", nullable = true)
	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	@Column(name = "sendEmailTime", nullable = true)
	public Date getSendEmailTime() {
		return sendEmailTime;
	}

	public void setSendEmailTime(Date sendEmailTime) {
		this.sendEmailTime = sendEmailTime;
	}

	@Column(name = "sendForgetEmailTime", nullable = true)
	public Date getSendForgetEmailTime() {
		return sendForgetEmailTime;
	}

	public void setSendForgetEmailTime(Date sendForgetEmailTime) {
		this.sendForgetEmailTime = sendForgetEmailTime;
	}

	@Column(name = "memBeginTime", nullable = true)
	public Date getMemBeginTime() {
		return memBeginTime;
	}

	public void setMemBeginTime(Date memBeginTime) {
		this.memBeginTime = memBeginTime;
	}

	@Column(name = "memEndTime", nullable = true)
	public Date getMemEndTime() {
		return memEndTime;
	}

	public void setMemEndTime(Date memEndTime) {
		this.memEndTime = memEndTime;
	}

	@Column(name = "isOnline", nullable = true)
	public Integer getIsOnline() {
		return isOnline;
	}

	public void setIsOnline(Integer isOnline) {
		this.isOnline = isOnline;
	}

	@Column(name = "loginTimes", nullable = true)
	public Integer getLoginTimes() {
		return loginTimes;
	}

	public void setLoginTimes(Integer loginTimes) {
		this.loginTimes = loginTimes;
	}

	@Column(name = "lastSignTime", nullable = true)
	public Date getLastSignTime() {
		return lastSignTime;
	}

	public void setLastSignTime(Date lastSignTime) {
		this.lastSignTime = lastSignTime;
	}

	@Column(name = "thisSignTime", nullable = true )
	public Date getThisSignTime() {
		return thisSignTime;
	}

	public void setThisSignTime(Date thisSignTime) {
		this.thisSignTime = thisSignTime;
	}

	@Column(name = "notes", nullable = true )
	public String getNotes() {
		return notes;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}

	@ManyToOne(targetEntity = UserGroupVOBean.class)
	@JoinColumn(name = "groupId", nullable = false)
	public UserGroupVOBean getGroup() {
		return group;
	}

	public void setGroup(UserGroupVOBean group) {
		this.group = group;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((email == null) ? 0 : email.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		UserVOBean other = (UserVOBean) obj;
		if (email == null) {
			if (other.email != null)
				return false;
		} else if (!email.equals(other.email))
			return false;
		return true;
	}
}
